package gorseclient

import (
	"fmt"
	"net/http"
	"net/url"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

func (c *DefaultGorse) CreateFeedback(fullUrl string, itemId, uid, fType string) error {
	// 创建一个包含所有参数的map
	data := url.Values{}
	data.Set("fType", fType) // 使用Set简化单个值的添加
	data.Set("userId", uid)
	data.Set("itemId", itemId)
	resp, err := http.Post(fullUrl+"/api/forum/recommended/createFeedback", "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
	if err != nil {
		logx.Errorw("[GORSE] Error calling the API:", logx.Field("detail", err.Error()), logx.Field("url", fullUrl), logx.Field("data", data.Encode()))
		return err
	}
	defer resp.Body.Close() // 确保响应体被关闭

	// 检查HTTP响应状态码
	if resp.StatusCode != http.StatusOK {
		// 可以根据需要处理不同的状态码
		err := fmt.Errorf("received non-200 response code: %d", resp.StatusCode)
		logx.Errorw("[GORSE] Non-success HTTP response:", logx.Field("detail", err.Error()), logx.Field("status_code", resp.StatusCode))
		return err
	}

	return nil
}
